#! /usr/bin/python
# -*- coding: cp1250 -*-
#sys.path.append(r'C:\AFT\.pylib')

import glob, sys, os, re, string
import pepe.p_txt.bigtxt as bt

zf4     = lambda x:   string.zfill(x, 4)

def __do(inpfile, cdelimiter):
    out = {}
    lino = 0
    for line in bt.lines(inpfile):
        line = re.sub('\n','',line)
        cols = string.split(line, cdelimiter)
        lino += 1
        if lino == 1:
            for c_index, c_value in enumerate(cols):
                out[zf4(c_index)] = [c_value,len(c_value),line]
        else:
            for c_index, c_value in enumerate(cols):
                if len(c_value) > out[zf4(c_index)][1]:
                    out[zf4(c_index)][0] = c_value
                    out[zf4(c_index)][1] = len(c_value)
                    out[zf4(c_index)][2] = line

    for k in sorted(out.keys()):
        print k, out[k]

HELP = """
Purpose:    Prints spans of csv file individual columns.
Syntax:     csv_cspan <inpfile> <cdelimiter>
Example:    csv_cspan test.csv \"|\"
"""

if __name__ == "__main__":
    #print __do("test.csv", "|", 1)
    #__do('data.dat', '^')
    if len(sys.argv) <> 3:
        print HELP
    else:
        __do(sys.argv[1], sys.argv[2])


